﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;

namespace Utils
{
	public class ObservableCollection2<T> : ObservableCollection<T>
	{
		public void AddRange(IEnumerable<T> items)
		{
			base.CheckReentrancy();

			List<T> addedItems = new List<T>(items);
			
			if (addedItems.Count > 0)
			{
				int startingIndex = this.Count;

				foreach (T item in addedItems)
				{
					base.Items.Add(item);
				}

				base.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
				base.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
				base.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedItems, startingIndex));
			}
		}
	}
}
